﻿<!DOCTYPE html>
<html>
<head>
    <title>添加栏目</title>
</head>
<body>
    <div class="tabarea1">
        <div id="area" class="area" style="overflow-y: auto;">
            <form action="" method="post" id="category_entity_form">
                <input type="hidden" name="lft" field="Lft" />
                <input type="hidden" name="plft" field="PLft" />
                <div class="form">
                    <p style="display:none"><span class="txt">上级栏目：</span><span class="input"><select class="tb_normal" field="parentLft" name="pcata" id="pcata"><option value="1" style="color:Red">根目录</option>${categories}</select></span><span class="desc">如果创建一级栏目,请选择"根目录"</span></p>


                    <dl><dt>名&nbsp;&nbsp;&nbsp;&nbsp;称：</dt><dd><input type="text" class=" ui-validate" id="name" field="Name" summary="{required:'不能为空',strerr:'长度为50位以下的字母，数字，下划线和连接线的组合'}" /></dd></dl>

                    <dl><dt>栏目标识：</dt><dd><input type="text" class=" ui-validate" name="tag" id="tag" field="Tag" /><a style="margin-left:5px" href="javascript:;" summary="{required:'不能为空',strerr:'长度为20位以下的字母，数字，下划线和连接线的组合'}">自动标识</a><br /><span class="desc" style="padding-left:60px">建议手动填写,用于调用数据的唯一标识,且显示在地址栏中,如http://www.ops.cc/news/,news就是一个标签</span></dd></dl>

                    <dl style="display:none"><dt>模&nbsp;&nbsp;&nbsp;&nbsp;块：</dt><dd><select class="tb_normal" _field="ModuleId">${categoryTypes}</select><span class="msg"></span></dd></dl>
                    <dl><dt>视&nbsp;&nbsp;&nbsp;&nbsp;图：</dt><dd><select field="CategoryTemplate" id="CategoryTemplate" class="tb_normal"><option value="">一默认一</option>${category_tpls}</select><span class="desc">注：默认则使用模块的视图设置</span></dd></dl>
                    <dl><dt>文档视图：</dt><dd><select field="CategoryArchiveTemplate" id="CategoryArchiveTemplate" class="tb_normal"><option value="">一默认一</option>${archive_tpls}</select><span class="desc">注：默认则使用模块（或文档）的视图设置</span></dd></dl>


                    <dl><dt>序号：</dt><dd><input class=" ui-validate" isnumber="true" field="OrderIndex" style="width:50px;" /></dd></dl>

                    <dl>
                        <dt>位置定向：</dt>
                        <dd>
                            <input class=" ui-validate" length="[0,150]" name="location" field="Location" />
                            访问栏目页面，跳转到的地址。默认不填写，不跳转!
                        </dd>
                    </dl>

                    <dl><dt>标题：</dt><dd><textarea class=" ui-validate" length="[0,100]" field="PageTitle" style="width:500px;height:25px;"></textarea></dd></dl>

                    <dl><dt>关&nbsp;键&nbsp;字：</dt><dd><textarea class=" ui-validate" length="[,100]" field="Keywords" style="width: 500px; height: 50px;"></textarea></dd></dl>
                    <dl><dt>描&nbsp;&nbsp;&nbsp;&nbsp;述：</dt><dd><textarea class=" ui-validate" length="[,200]" field="Description" style="width: 500px; height: 75px;"></textarea></dd></dl>
                    <dl><dt>&nbsp;</dt><dd><a id="btn" class="btn" href="javascript:;">保存</a></dd></dl>
                </div>
            </form>
        </div>
    </div>
    <script type="text/javascript">
        cms.val('pcata', '${pleft}');

        cms.val('CategoryTemplate', '${categoryTplPath}');
        cms.val('CategoryArchiveTemplate', '${archiveTplPath}');
        cms.json.bind('category_entity_form',${entityJson});

        var tag = cms.$("tag"),
        name = cms.$("name");

        tag.onblur = function () {
            if (tag.value == '') {
                cms.validator.setTip(tag.nextSibling, false, 'required');
            } else {
                tag.value = tag.value.toLowerCase();
                if (!/^[a-z0-9_-]{1,50}$/.test(tag.value)) {
                    cms.validator.setTip(tag.nextSibling, false, 'strerr');
                } else {
                    cms.validator.removeTip(tag.nextSibling);
                }
            }
        };

        name.onblur = function () {
            if (name.value == '') {
                cms.validator.setTip(name, false,'required');
            } else {
                if (name.value.length > 50) {
                    cms.validator.setTip(name, false,'lenerr');
                } else {
                    cms.validator.removeTip(name);
                }
            }
        };

        tag.nextSibling.onclick = function () {
            var e = this;
            var txt = this.innerHTML;
            var _title = name.value;
            if (_title == '') {
                cms.validator.setTip(e, false, null, '请先栏目名称!');
            } else {
                this.innerHTML = '获取中...';
                cms.xhr.post('?', 'module=archive&action=GetArchiveAlias&title=' + encodeURIComponent(_title), function (result) {
                    e.previousSibling.value = result.toLowerCase();
                    e.previousSibling.onblur();
                    e.innerHTML = txt;
                }, function () {
                    cms.validator.setTip(e, false, null, '获取失败,请重试!');
                });
            }
        };


        var isEdit = location.hash.split('.')[1] == 'update';

        cms.$('btn').onclick = function () {
            if (cms.validator.validate()) {
                var data=cms.json.toObject('category_entity_form');
                
                cms.xhr.jsonAjax(
                    '${url}',
                     data,
                     function (json) {
                         if (json.result) {
                             if (window.Fn.loadData) {
                                 window.Fn.loadData();
                                 if (window.parent.M) {
                                     window.parent.M.loadCatTree();
                                 }
                             } else {
                                 parent.M.tip(json.message, function () {
                                     location.replace('?module=category&action=all');
                                 });
                             }
                         }
                         parent.M.tip(json.message);
                     });
            }
        };


    </script>
</body>
</html>
